package game.controller
{
	import com.greensock.loading.SWFLoader;
	import com.greensock.loading.XMLLoader;
	
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import game.event.EventName;
	import game.event.GameEvent;
	import game.managers.ConfigManager;
	import game.managers.LayerManager;
	import game.managers.UIManager;
	import game.utils.MassLoader;
	import game.view.scene.LoadingView;

	/**
	 * 
	 * @author xiezhicheng
	 */
	public class LoginCenter extends BaseCenter
	{
		private static var instance:LoginCenter;
		private var loadingView:LoadingView;
		
		/**判断是否加载主UI*/
		private var loaded:Boolean;
		
		public function LoginCenter()
		{
			if(instance == null){
				instance = this;
				init();
			}else{
				throw new Error("LoginCenter is a single class");
			}
		}
		
		
		public static function getInstance():LoginCenter
		{
			if(instance == null)
				instance = new LoginCenter();
			return instance;
		}
		
		
		private function init():void
		{
		}
		
		
		/**
		 * 登录
		 * */
		private function loginSuccessHave():void
		{
			var arr:Array=[];

			arr.push(new SWFLoader(ConfigManager.uiURL + "loading.swf",{name:"loading"}));
			arr.push(new SWFLoader(ConfigManager.uiURL + "ui.swf",{name:"ui"}));
			arr.push(new XMLLoader(ConfigManager.dataURL + "map.xml",{name:"mapxml"}));
			arr.push(new XMLLoader(ConfigManager.dataURL + "data.xml",{name:"dataxml"}));
			
			loadingView.loadRes(arr,loadComplete);
		}
		
		private function loadComplete():void
		{
			loadingView.dispose();	
			loadingView = null;
			UIManager.loadingView = null;

			GameCenter.getInstance().initControllers();
		}
		
		
		public function showLoadingView():void
		{
			loadingView = new LoadingView();
			loadingView.layout();
			LayerManager.uiLayer.addChild(loadingView);
			UIManager.loadingView = loadingView;	
			
			loginSuccessHave();
		}
		
	}
}